﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using HandlingInput;
using GameCore;

namespace GameObject
{
    public class ActionButton: Button
    {
        int time_wait = 0;
        int time_cout = 0;
        int wait_step = 1; // Bước nhảy mỗi khi đợi


        public override event Window.GetEvent Enter;
        public override event Window.GetEvent Hover;
        public override event Window.GetEvent Normal;

        public int Wait_step
        {
            get { return wait_step; }
            set { wait_step = value; }
        }

        public void Active_Wait(int time)
        {
            time_wait = time;
            time_cout = time;
        }
        public bool is_wait()
        {
            return (time_cout >= 0);
        }
        public void Wait(GameTime gameTime)
        {
            time_cout -= wait_step;
            _lsprite.Add(new Vector2( 1, 0));
            int y_cout = (int)(((float)this.Height/time_wait)*(time_wait-time_cout));
            _sprite[1].Update(gameTime, 0, this.X,
                this.Y + y_cout, this.Width, this.Height - y_cout);

        }
        public override void Update(Microsoft.Xna.Framework.GameTime gameTime, float x, float y, int w, int h)
        {

            if (is_wait())
            {
                Enable = false;

                _lsprite.Add(new Vector2(0, s_click));
                show_text = true;
            }
            else
            {
                Enable = true;
                show_text = false;
               
            }

            base.Update(gameTime, x, y, w, h);

            if (is_wait())
                Wait(gameTime);
        }
        public override VisibleGameObject Clone()
        {
            VisibleGameObject newObj = new ActionButton();

           
            newObj._nsprite = this._nsprite;
            ((ActionButton)newObj).TextDisplay = this.TextDisplay;
            ((ActionButton)newObj).Font = this.Font;
            newObj._sprite = new Sprite[_nsprite];
            for (int i = 0; i < _nsprite; i++)
            {
                newObj._sprite[i] = _sprite[i].Clone() ;
            }
            newObj.X = this.X;
            newObj.Y = this.Y;
            newObj.Width = this.Width;
            newObj.Height = this.Height;
            newObj._lsprite = new List<Vector2>();

            ((ActionButton)newObj).Enter = this.Enter;
            ((ActionButton)newObj).Hover = this.Hover;
            ((ActionButton)newObj).Normal = this.Normal;
            return newObj;
        }
    }
}
